'use strict';

var mongoose = require('mongoose'),
    Schema = mongoose.Schema;

var ReportSchema = new Schema({
  title: String,
  date: Date,
  body: String,
  plan: String,
  notes: String,
  type: String,
  user: {
    type: Schema.Types.ObjectId,
    ref: 'User'
  },
  files: [{
    type: Schema.Types.ObjectId,
    ref: 'Document'
  }],
  created_at: {type: Date, default: Date.now},
  updated_at: {type: Date, default: Date.now}
});

ReportSchema
  .pre('save', function(next) {
    if (!this.isNew) this.updated_at = Date.now;
    next();
  });
module.exports = mongoose.model('Report', ReportSchema);
